﻿using JobBack.Models;
using QG.JobBack.BLL.IService;
using QG.JobBack.DAL;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JobBack.Controllers
{
    public class PictureController : Controller
    {
        //图片业务层接口
        private IPictureService ipictureService;
        
        private Opretation opretation = new Opretation();
        public PictureController(IPictureService ipictureService)
        {
            this.ipictureService = ipictureService;
        }
        /// <summary>
        /// 图片管理页面
        /// </summary>
        /// <returns></returns>
        public ActionResult PictureManager()
        {
            List<PictureInfo> pictureInfo = new List<PictureInfo>();
            ViewBag.pictureInfo = pictureInfo;
            return View();
        }
        /// <summary>
        /// 新增图片页面
        /// </summary>
        /// <returns></returns>
        public ActionResult PictureAdd()
        {
            return View();
        }
        public ActionResult PictureUpdate()
        {
            return View();
        }
        /// <summary>
        /// 图片信息分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="PicName"></param>
        /// <param name="Status"></param>
        /// <param name="CreateTime"></param>
        /// <returns></returns>
        public JsonResult SelectPitureTable(int page, int limit,string PicName, Nullable<bool> Status, Nullable<DateTime> CreateTime)
        {
            List<PictureInfoBase> pinfo = ipictureService.QueryPictureAll(PicName, Status, CreateTime);
                //ipictureService.QueryPageList(page, limit, a => true, a => a.PicId);
            ResponseResult<PictureInfoBase> getJson = new ResponseResult<PictureInfoBase>()
            {
                msg = "",
                code = 0,
                count = pinfo.Count,
                data = pinfo.Skip((page - 1) * limit).Take(limit).ToList()
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 删除一条图片信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeletePictureInfo(int id)
        {
            //PictureInfo pinfo = new PictureInfo();
            //pinfo.PicId = Convert.ToInt32(id);
            //opretation.Success = ipictureService.DeletePictureInfo(pinfo.PicId);
            opretation.Success = ipictureService.Delete(id);
            return Json(opretation);

        }
        /// <summary>
        /// 添加一条图片信息
        /// </summary>
        /// <param name="pictureInfo"></param>
        /// <returns></returns>
        public JsonResult AddPictureInfo(PictureInfo pictureInfo)
        {
            pictureInfo.CreateTime = DateTime.Now;
            opretation.Success=ipictureService.Add(pictureInfo);
            return Json(opretation);
        }
        /// <summary>
        /// 修改一条图片信息
        /// </summary>
        /// <param name="pictureInfo"></param>
        /// <returns></returns>
        public JsonResult UpdatePictureInfo(PictureInfo pictureInfo)
        {
            opretation.Success = ipictureService.Update(pictureInfo);
            return Json(opretation);
        }

        /// <summary>
        ///传入一个对象修改图片状态
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdatePictureStar(PictureInfo pictureInfo)
        {    
            opretation.Success = ipictureService.UpdatePictureStar(pictureInfo);
            return Json(opretation);
        }
    }
}